<template>
    <uni-popup ref="popup" type="center" background-color="transparent" @maskClick="changeAgreed">
        <view class="popup_box">
            <image class="dun" src="/static/dun.png" mode="" />
            <view class="title">温馨提示</view>
            <view class="desp"
                >为了保护您的个人信息安全，<text
                    class="u_line"
                    @tap="goUserAgreement"
                    >《用户协议》</text
                >
                和<text class="u_line" @tap="goPrivacyPolicy">《隐私协议》</text
                >告知我们如何手机个人信息 如和使用及存储个人信息，及您享有的相关
                权力，点击“同意”相关协议条款，“不同意”将退出App。</view
            >
            <view
                class="btn_main_r"
                style="width: 480rpx; margin-top: 50rpx"
                @tap="agree"
            >
                <text class="text">同意</text>
            </view>

            <view
                class="btn_main_r_line"
                style="width: 480rpx; margin-top: 20rpx"
                @tap="exit"
            >
                <text class="text">不同意并且退出</text>
            </view>
        </view>
    </uni-popup>
</template>

<script setup lang="ts">
import { ref,computed } from "vue";
import { config as configStore } from "@/store/config";
import { wait } from '@/utils/utils'
const emit = defineEmits(["agree"]);
const config: any = configStore();

const goUserAgreement = ()=>{
    uni.navigateTo({
		url:`/pages/webview/webview?title=用户协议&url=http://52pp365.com/yonghuxieyi.html`
	});
}

const goPrivacyPolicy = ()=>{
    uni.navigateTo({
		url:`/pages/webview/webview?title=隐私政策&url=http://52pp365.com/yinsizhengce.html`
	});
}

const popup = ref(null);

let agreed = null;


const open = ()=>{
    const hasOpened = uni.getStorageSync('popup_readed');
    if(!hasOpened){
        popup.value.open();
    }

}
const open1 = async()=>{
    agreed = null;
    popup.value.open();
    // const hasOpened = uni.getStorageSync('popup_readed');
    // if(!hasOpened){
    //     popup.value.open();
    // }
    return await checkAgreed();

}

const changeAgreed = ()=>{
    agreed = false;
}


const checkAgreed = async()=>{
    if(agreed===null){
        await wait(1000);
        return await checkAgreed();
    }

    return agreed;
}

const agree = ()=>{
    agreed = true;
    uni.setStorageSync('popup_readed',true);
    config.setConfig({agreement:true});
    popup.value.close();
    emit('agree');
}

const exit = ()=>{
    if(uni.getSystemInfoSync().platform==='ios'){
        plus.ios.import("UIApplication").sharedApplication().performSelector("exit");
    }
    if(uni.getSystemInfoSync().platform==='android'){
        plus.runtime.quit();
    }
}


defineExpose({
  open,
  open1,
})


</script>
<style lang="scss" scoped>
.popup_box{
    width:584rpx;
    height:710rpx;
    padding:45rpx;
    background: linear-gradient(27deg, #D6F6FC 0%, #EAFCE1 59%, #B2FACD 100%);
    border-radius: 20rpx;
    .u_line{
        text-decoration: underline;
        color:#1DC691;
    }
    .dun{
        width:100rpx;
        height:142rpx;
        margin:0 auto;
    }

    .title{
        color:#333;
        font-size:34rpx;
        margin-top:-10rpx;
    }

    .desp{
        color:#585859;
        font-size:26rpx;
        text-align: left;
        margin-top:20rpx;
    }

}
</style>

